package br.com.techfor.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.com.techfor.command.InterfaceCommand;
import br.com.techfor.model.helper.Helper;

public class RequestResponseController extends javax.servlet.http.HttpServlet
		implements javax.servlet.Servlet {

	static final long serialVersionUID = 1L;

	public RequestResponseController() {
		super();
	}

	private void requestProcess(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		Helper helper = new Helper(request);
		InterfaceCommand interfaceCommand = helper.getCommand();
		String pagina = interfaceCommand.execute(request, response);
		request.getRequestDispatcher(pagina).forward(request, response);

	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		this.requestProcess(request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		this.requestProcess(request, response);
	}

}
